package com.lingshu.core.custom;

import androidx.annotation.NonNull;

import java.text.DateFormat;

/**
 * @author 于定金
 * @version 1.0
 * @Date 2024/1/4 11:23
 * @Description
 */
public abstract class BaseExceptionHandler implements Thread.UncaughtExceptionHandler {
    public static final String TAG = "CrashHandler";
    protected static final DateFormat DATE_FORMAT = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);

    @Override
    public void uncaughtException(@NonNull Thread t, @NonNull Throwable ex) {
        //如果正确处理了未捕获异常
        if (handlerException(ex)) {
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            //退出程序
            android.os.Process.killProcess(android.os.Process.myPid());
            System.exit(1);
        }
    }

    public abstract boolean handlerException(Throwable throwable);
}
